/*
 * Image.cpp
 *
 *  Created on: 2012-10-18
 *      Author: yangentao@gmail.com
 */
#include "Image.h"

Bitmap::Bitmap() :
		hBitmap(0) {

}
Bitmap::Bitmap(HBITMAP hBmp) :
		hBitmap(hBmp) {

}
Bitmap::~Bitmap() {
//	release();
}
void Bitmap::release() {
	if (hBitmap) {
		BOOL b = DeleteObject(hBitmap);
		if(!b){
			throw ObjectInuseException();
		}
	}
	hBitmap = 0;
}
HBITMAP Bitmap::discard() {
	HBITMAP b = hBitmap;
	hBitmap = 0;
	return b;
}
void Bitmap::create32(int width, int height, void* bits){
	assert(!hBitmap);
	hBitmap = CreateBitmap(width, height, 1, 32, bits);
}
bool Bitmap::enable(){
	return hBitmap !=0;
}
Bitmap::operator HBITMAP(){
	return hBitmap;
}
Size Bitmap::getSize() {
	BITMAP bmp = { 0 };
	GetObject(hBitmap, sizeof(bmp), &bmp);
	return Size(bmp.bmWidth, bmp.bmHeight);
}
int Bitmap::getWidth() {
	BITMAP bmp = { 0 };
	GetObject(hBitmap, sizeof(bmp), &bmp);
	return bmp.bmWidth;
}
int Bitmap::getHeight() {
	BITMAP bmp = { 0 };
	GetObject(hBitmap, sizeof(bmp), &bmp);
	return bmp.bmHeight;
}
